{% extends "base_worklist.html" %}
{%block title%}
Hastane Faturaları (içerik)
{%endblock%}

{%block content%}
	
	{% load work_custom_filters  %}
	
	<div style="width:1000px; margin-left: auto; margin-right: auto;">
	   <fieldset class="module aligned ">
			
		    	<div class="form-row category  "> 
			    	<div id="content" class="flex">
				    <div id="content-main">
					    	<ul class="object-tools">
					          <li>
					            {% if fat_id %}
					            <a href="/worklist/hastane/fatura/" class="addlink">
					            {% else %}
					            <a href="#" id="fatbox-slidetoggle" class="addlink">
					            {% endif %}
					              Fatura Ekle
					            </a>
					          </li>
					          
					        </ul>
					</div>
					</div> 
				 
		    		<table style="width: 1000px;">
						<caption class="section">Kaydedilmiş Faturalar</caption>
						<tbody>
							<thead>
								<th>#</th>
								<th>Kurum</th>
								<th>Fat.Tarih</th>
								<th>Fat.No</th>
								<th>Açıklama</th>
														
							</thead>
							{% if fatlist %}
							{% for fat in fatlist %}
							
								<tr {% ifequal fat.id fat_id %}style="background: #FFFF99;"{% endifequal %}>
									<td colspan="1" style="vertical-align: middle;"><b><a href="/worklist/hastane/fatura/?fat_id={{fat.id}}">{{forloop.counter}}</a></b></td>
									<td style="vertical-align: middle;"><a href="/worklist/hastane/fatura/?fat_id={{fat.id}}">{{fat.cari}}</a></td>
									<td style="vertical-align: middle;"><a href="/worklist/hastane/fatura/?fat_id={{fat.id}}">{{fat.fatura_tarih}}</a></td>
									<td style="vertical-align: middle;"><a href="/worklist/hastane/fatura/?fat_id={{fat.id}}">{{fat.fatura_no}}</a></td>
									<td style="vertical-align: middle;"><a href="/worklist/hastane/fatura/?fat_id={{fat.id}}">{{fat.aciklama}}</a></td>
		 						</tr>
									
							
							{% endfor %}
							{% endif %}
							
						</tbody>
				    </table>
				    
    			    
		    	</div>
		    </fieldset>
		    
	</div>
	
	{% if faturaform %}
	<div id="fatbox" style="width:1000px; margin-left: auto; margin-right: auto;">
		    <fieldset class="module aligned ">
		    	<div class="form-row category  "> 
		    	    <form action="/worklist/hastane/fatura/kaydet/" method="POST">
		    		<table style="width: 1000px;">
		    		<caption class="section">Fatura Bilgileri</caption>
		    		<tbody>
		    		<thead>
								<th>Kurum</th>
								<th>Fat.Tarih</th>
								<th>Fat.No</th>
								<th>Açıklama</th>
														
					</thead>
		       		
		       		  <tr>
		       		  	<td style="vertical-align: middle;">{{faturaform.cari}}{% if faturaform.cari.errors %}<small>{{faturaform.cari.errors}}</small>{%endif%}</td>
		       		  	<td style="vertical-align: middle;">{{faturaform.fatura_tarih}}&nbsp;<a href="javascript:NewCssCal('id_fatura_tarih','yyyymmdd','arrow',false,24,false)"><img src="/media/images/cal.gif" width="16" height="16" alt="Pick a date"></a>{% if faturaform.fatura_tarih.errors %}<small>{{faturaform.fatura_tarih.errors}}</small>{%endif%}</td>
		       		  	<td style="vertical-align: middle;">{{faturaform.fatura_no}}{% if faturaform.fatura_no.errors %}<small>{{faturatarihi.fatura_no.errors}}</small>{%endif%}</td>
		       	  		<td style="vertical-align: middle;">{{faturaform.aciklama}}{% if faturaform.aciklama.errors %}<small>{{faturaform.aciklama.errors}}</small>{%endif%}&nbsp;</td>
		       		  	
		       		  </tr>
		       	
		       		</tbody>
		    		</table>
		    		
			    		<div class="submit-row" >
			    			<input type="button" value="Fatura Detayları" id="slick-slidetoggle" class="default" name="_detaylar" />
			    			<input type="submit" value="Kaydet" onclick="this.disabled=true;this.value='ekliyor..';this.form.submit();" class="default" name="_save" />
							<input type="submit" value="Kaydet ve düzenlemeye devam et" name="_continue" />
			  		    	
			  		    </div>
					</form>
		    	</div>
		    	 
			    <div id="slickbox" class="form-row category  "> 
			    		
			    		<table style="width: 1000px;">
			    		<caption class="section">&nbsp;Fatura Detaylar</caption>
			       		<tbody>
			       		<thead>
			       			<th>Açıklama</th>
			       			<th>Fiyat</th>
			       			<th>Miktar</th>
			       			<th>Birim</th>
			       			<th>Kdv</th>
			       			<th>___</th>
			       		</thead>
 		       			<tr>
 		       			<form action="/worklist/hastane/fatura/kaydet/" method="POST">
							<td width="60%">{{faturadetayform.aciklama}}</td>	
							<td width="10%">{{faturadetayform.price}}</td>
							<td width="5%">{{faturadetayform.quantity}}</td>
							<td width="10%">{{faturadetayform.unit}}</td>		
							<td width="5%"><select name="tax_ratio" id="id_tax_ratip">
											<option value="8" selected="selected">8</option>
											<option value="18">18</option>
											<option value="1">1</option>
																		</select></td>
							<td width="5%"><a href ="javascript:void(0);" onclick="return(0);"><img alt="Taslaktan Bakım Formu Oluştur" title="Taslaktan Bakım Formu Oluştur" src="/media/images/go.gif"></img></a></td>
			       		</tr>
			       		  
			       	
			       		</tbody>
			    		</table>
			    </div>
			     
		    </fieldset>
		    
		</div>
	
		    {% if faturaform.errors %}
		    <div style="width:1000px; margin-left: auto; margin-right: auto;">
		    <fieldset class="module aligned ">
		        <p style="color: red;">
		           Bilgilerinizde hata var.. Lütfen Düzeltin ({{ faturaform.errors|length }}).
		        </p>
		        <ul>
		        {% for errors in faturaform.errors.items %}
    				{% for error in errors %}
		       			<li>{{error}}</li>
		       		{% endfor %}
		       	{%endfor%}
		       </ul> 		
		    </fieldset>
		    </div>
		    {% endif %}
			
	{% endif %}
	
	{% if faturaeditform %}
		<div style="width:1000px; margin-left: auto; margin-right: auto;">
		    <fieldset class="module aligned ">
		    	<div class="form-row category  "> 
		    	    <form action="/worklist/hastane/fatura/{{fat_id}}/degistir/" method="POST">
		    		<table style="width: 1000px;">
		    		<caption class="section">Fatura Bilgileri</caption>
		       		<tbody>
		       		<thead>
								<th>Kurum</th>
								<th>Fat.Tarih</th>
								<th>Fat.No</th>
								<th>Açıklama</th>
														
					</thead>
		       		  <tr>
		       		  	<td style="vertical-align: middle;">{{faturaeditform.cari}}{% if faturaeditform.cari.errors %}<small>{{faturaeditform.cari.errors}}</small>{%endif%}</td>
		       		  	<td style="vertical-align: middle;">{{faturaeditform.fatura_tarih}}&nbsp;<a href="javascript:NewCssCal('id_fatura_tarih','yyyymmdd','arrow',false,24,false)"><img src="/media/images/cal.gif" width="16" height="16" alt="Pick a date"></a>{% if faturaeditform.fatura_tarih.errors %}<small>{{faturaeditform.fatura_tarih.errors}}</small>{%endif%}</td>
		       		  	<td style="vertical-align: middle;">{{faturaeditform.fatura_no}}{% if faturaeditform.fatura_no.errors %}<small>{{faturatarihi.fatura_no.errors}}</small>{%endif%}</td>
		       	  		<td style="vertical-align: middle;">{{faturaeditform.aciklama}}{% if faturaeditform.aciklama.errors %}<small>{{faturaeditform.aciklama.errors}}</small>{%endif%}&nbsp;</td>
		       		  	
		       		  </tr>
		       	
		       		</tbody>
		    		</table>
		    		
			    		<div class="submit-row" >
			    			<input type="button" value="Fatura Detayları" id="slick-slidetoggle" class="default" name="_detaylar" />
			    			<input type="submit" value="Kaydet" onclick="this.disabled=true;this.value='ekliyor..';this.form.submit();" class="default" name="_save" />
							<input type="submit" value="Kaydet ve düzenlemeye devam et" name="_continue" />
			  		    </div>
					</form>
		    	</div>
		    	
		    	<div id="slickbox" class="form-row category  "> 
			    		
			    		<table style="width: 1000px;">
			    		<caption class="section">&nbsp;Fatura Detaylar</caption>
			       		<tbody>
			       		<thead>
			       			<th>Açıklama</th>
			       			<th>Fiyat</th>
			       			<th>Miktar</th>
			       			<th>Birim</th>
			       			<th>Kdv</th>
			       			<th>&nbsp;</th>
			       		</thead>
			       		{% if fdetaylist %}
				       		{% for fd in fdetaylist %}
				       		<tr {% ifequal fd.id fatdetay_id %}style="background: #CCFFCC;"{% endifequal %}>    
 		       				<td width="60%" style="vertical-align: middle;">{{fd.aciklama}}</td>	
							<td width="10%" style="vertical-align: middle;">{{fd.price|floatformat:2}}</td>
							<td width="5%" style="vertical-align: middle;">{{fd.quantity}}</td>
							<td width="10%" style="vertical-align: middle;">{{fd.unit}}</td>		
							<td width="5%" style="vertical-align: middle;">{{fd.tax_ratio}}</td>
							<td width="5%" style="vertical-align: middle;"><a href="/worklist/hastane/fatura/{{fat_id}}/detay/{{fd.id}}/"><img alt="edit" title="Satır Düzenle" src="/media/images/go.gif"/></a></td>
			       		</tr>
				       		{% endfor %}
	 		       		{% endif %}
 		       			{% if fatdetay_id %}
 		       			<form id="fatdetay" action="/worklist/hastane/fatura/{{fat_id}}/detay/{{fatdetay_id|default_if_none:"0"}}/kaydet/" method="POST">
 		       			{% else %}
 		       			<form id="fatdetay" action="/worklist/hastane/fatura/{{fat_id}}/detay/ekle/" method="POST">
 		       			{% endif %}
 		       			<tr>    
 		       				<td width="60%" style="vertical-align: middle;">{{faturadetayform.aciklama}}{% if faturadetayform.aciklama.errors %}<br>{{faturadetayform.aciklama.errors}}{%endif%}</td>	
							<td width="10%" style="vertical-align: middle;">{{faturadetayform.price}}{% if faturadetayform.price.errors %}<br>{{faturadetayform.price.errors}}{%endif%}</td>
							<td width="5%" style="vertical-align: middle;">{{faturadetayform.quantity}}{% if faturadetayform.quantity.errors %}<br>{{faturadetayform.quantity.errors}}{%endif%}</td>
							<td width="10%" style="vertical-align: middle;">{{faturadetayform.unit}}{% if faturadetayform.unit.errors %}<br>{{faturadetayform.unit.errors}}{%endif%}</td>		
							<td width="5%" style="vertical-align: middle;"><select name="tax_ratio" id="id_tax_ratio">
											<option value="8" selected="selected">8</option>
											<option value="18">18</option>
											<option value="1">1</option>
																		</select></td>
							<td width="5%" style="vertical-align: middle;"><input type="submit" {% if fatdetay_id %}value="Kaydet"{%else%}value="Ekle"{%endif%} onclick="this.disabled=true;this.value='Deniyor..';this.form.submit();" class="default" name="_save" /></td>
			       		</tr>
			       		</form>
			       	
			       		</tbody>
			    		</table>
			      
			    </div>
		    </fieldset>
		    
		</div>
	
		    {% if faturaform.errors %}
		    <div style="width:1000px; margin-left: auto; margin-right: auto;">
		    <fieldset class="module aligned ">
		        <p style="color: red;">
		           Bilgilerinizde hata var.. Lütfen Düzeltin ({{ faturaform.errors|length }}).
		        </p>
		        <ul>
		        {% for errors in faturaform.errors.items %}
    				{% for error in errors %}
		       			<li>{{error}}</li>
		       		{% endfor %}
		       	{%endfor%}
		       </ul> 		
		    </fieldset>
		    </div>
		    {% endif %}
	{% endif %}
{%endblock%}
{% block script %}
<script type="text/javascript" src="/media/js/jquery.formatcurrency.js"></script>

<script type="text/javascript" charset="utf-8"> 

		$(document).ready(function() {

			// hides the slickbox as soon as the DOM is ready
		  {% if not fdetaylist %}
			  $('#slickbox').hide();
		
		  {% endif %}
  		  $('#fatbox').hide();
		 // toggles the slickbox on clicking the noted link
		 
		  $('#slick-slidetoggle').click(function() {
			    $('#slickbox').slideToggle(400);
			    return false;
			  });

		  $('#fatbox-slidetoggle').click(function() {
			    $('#fatbox').slideToggle(400);
			    return false;
			  });

		  $(function() {

			   	// jQuery formatCurrency plugin: http://plugins.jquery.com/project/formatCurrency
				// formatWhileTypingAndWarnOnDecimalsEntered2
				// Format while typing & warn on decimals entered, 2 decimal places
				//$('input[alt="formatWhileTypingAndWarnOnDecimalsEntered2"]')
				$('input[alt="formatWhileTypingAndWarnOnDecimalsEntered2"]').blur(function() {
					//$('#formatWhileTypingAndWarnOnDecimalsEnteredNotification2').html(null);
					$(this).formatCurrency({ colorize: true, negativeFormat: '-%s%n', roundToDecimalPlace: 2 });
				})
				.keyup(function(e) {
					var e = window.event || e;
					var keyUnicode = e.charCode || e.keyCode;
					if (e !== undefined) {
						switch (keyUnicode) {
							case 16: break; // Shift
							case 17: break; // Ctrl
							case 18: break; // Alt
							case 27: this.value = ''; break; // Esc: clear entry
							case 35: break; // End
							case 36: break; // Home
							case 37: break; // cursor left
							case 38: break; // cursor up
							case 39: break; // cursor right
							case 40: break; // cursor down
							case 78: break; // N (Opera 9.63+ maps the "." from the number key section to the "N" key too!) (See: http://unixpapa.com/js/key.html search for ". Del")
							case 110: break; // . number block (Opera 9.63+ maps the "." from the number block to the "N" key (78) !!!)
							case 190: break; // .
							default: $(this).formatCurrency({ colorize: true, negativeFormat: '-%s%n', roundToDecimalPlace: -1, eventOnDecimalsEntered: true });
						}
					}
				})
				.bind('decimalsEntered', function(e, cents) {
					if (String(cents).length > 2) {
						var errorMsg = 'Please do not enter any cents (0.' + cents + ')';
						$('#formatWhileTypingAndWarnOnDecimalsEnteredNotification2').html(errorMsg);
						log('Event on decimals entered: ' + errorMsg);
					}
				});


				// Warn on decimals entered, 2 decimal places
				$('#warnOnDecimalsEntered2').blur(function() {
					$('#warnOnDecimalsEnteredNotification2').html(null);
					$(this).formatCurrency({ roundToDecimalPlace: 2, eventOnDecimalsEntered: true });
				})
				.bind('decimalsEntered', function(e, cents) {
					var errorMsg = 'Please do not enter any cents (0.' + cents + ')';
					$('#warnOnDecimalsEnteredNotification2').html(errorMsg);
					log('Event on decimals entered: ' + errorMsg);
				});


				// Format while typing & warn on decimals entered, no cents
				$('#formatWhileTypingAndWarnOnDecimalsEntered').blur(function() {
					$('#formatWhileTypingAndWarnOnDecimalsEnteredNotification').html(null);
					$(this).formatCurrency({ colorize: true, negativeFormat: '-%s%n', roundToDecimalPlace: 0 });
				})
				.keyup(function(e) {
					var e = window.event || e;
					var keyUnicode = e.charCode || e.keyCode;
					if (e !== undefined) {
						switch (keyUnicode) {
							case 16: break; // Shift
							case 27: this.value = ''; break; // Esc: clear entry
							case 35: break; // End
							case 36: break; // Home
							case 37: break; // cursor left
							case 38: break; // cursor up
							case 39: break; // cursor right
							case 40: break; // cursor down
							case 78: break; // N (Opera 9.63+ maps the "." from the number key section to the "N" key too!) (See: http://unixpapa.com/js/key.html search for ". Del")
							case 110: break; // . number block (Opera 9.63+ maps the "." from the number block to the "N" key (78) !!!)
							case 190: break; // .
							default: $(this).formatCurrency({ colorize: true, negativeFormat: '-%s%n', roundToDecimalPlace: -1, eventOnDecimalsEntered: true });
						}
					}
				})
				.bind('decimalsEntered', function(e, cents) {
					var errorMsg = 'Please do not enter any cents (0.' + cents + ')';
					$('#formatWhileTypingAndWarnOnDecimalsEnteredNotification').html(errorMsg);
					log('Event on decimals entered: ' + errorMsg);
				});


				// Warn on decimals entered, no cents
				$('#warnOnDecimalsEntered').blur(function() {
					$('#warnOnDecimalsEnteredNotification').html(null);
					$(this).formatCurrency({ roundToDecimalPlace: 0, eventOnDecimalsEntered: true });
				})
				.bind('decimalsEntered', function(e, cents) {
					var errorMsg = 'Please do not enter any cents (0.' + cents + ')';
					$('#warnOnDecimalsEnteredNotification').html(errorMsg);
					log('Event on decimals entered: ' + errorMsg);
				});


				function log(text) {
					$('#divLog').prepend('<div>' + text + '</div>');
				}
				
				$('#clearLog').click(function() {
					$('#divLog').empty();
				});

			});
			 
		  	  
		});
</script>
{% endblock %}